package com.emergency.examine.dao;

import com.emergency.examine.domain.Option;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface OptionDao extends JpaRepository<Option, Long>, JpaSpecificationExecutor<Option> {
    @Query("select op from Option op where question.id = :questionId")
    List<Option> findAllByQuestion(Long questionId);

    @Modifying
    @Transactional
    @Query(value = "delete FROM ex_option WHERE quest_id = ? ", nativeQuery = true)
    void deleteByQuestionId(Long questionId);
}
